<template>
  <div o-Container>
    <!-- created: create, -->
    <!-- v-bind="{ exported: output }" -->
    <o-list v-bind:source="list.contract" v-bind="{ exported: output }">
      <template slot="config" slot-scope="scope">
        <div class="img_box">
          <img
            @click="showLookDiaolog(scope)"
            src="/static/skin/default/MCS/AIGC/Inventory/images/chakan.png"
            alt=""
          />
        </div>
      </template>
    </o-list>
    <SalesOrderMsg
      ref="SalesOrderMsg"
      :messageList="messageList"
      @refresh="refresh"
    ></SalesOrderMsg>
    <SalesOrderMsg_SPOMS
      ref="SalesOrderMsg_SPOMS"
      :messageList="messageList"
      @refresh="refresh"
    ></SalesOrderMsg_SPOMS>
    <AfterSaleOrderMsg
      ref="AfterSaleOrderMsg"
      :messageList="messageList"
       @refresh="refresh"
    ></AfterSaleOrderMsg>
    <AfterSaleOrderMsg_SPOMS
      ref="AfterSaleOrderMsg_SPOMS"
      :messageList="messageList"
       @refresh="refresh"
    ></AfterSaleOrderMsg_SPOMS>
  </div>
</template>

<script>
import SalesOrderMsg from "../Components/SalesOrderMsg.vue";
import SalesOrderMsg_SPOMS from "../Components/SalesOrderMsg_SPOMS.vue";
import AfterSaleOrderMsg from "./../Components/AfterSaleOrderMsg.vue";
import AfterSaleOrderMsg_SPOMS from "./../Components/AfterSaleOrderMsg_SPOMS.vue";
export default {
  components: {
    SalesOrderMsg,
    SalesOrderMsg_SPOMS,
    AfterSaleOrderMsg,
    AfterSaleOrderMsg_SPOMS
  },
  name:
    "mms_platform_company_list" /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */,
  data() {
    return {
      octopus: this.$parent.octopus,
      list: {
        contract: {
          data: {
            id: 1183, // 菜单表的八爪鱼ID
            cellData: [
              { name: "Code", width: 180, searchKey: "like" }, // 订单编号
              { name: "NAME", width: 360 }, // 权益名称
              { name: "PurchaseName" }, // 买家
              { name: "PlatformID" }, // 购买渠道
              { name: "MerchantID", show: false }, // 买家
              { name: "PurchaserID", width: 200 , show: false}, // 买家
              { name: "Quantity" }, // 购买数量
              { name: "TotalPrice" }, // 下单金额（元）
              { name: "ServiceCompanyName" }, // 服务方
              { name: "CompanyID", show: false }, // 卖家
              { name: "PurchaseCompanyName" }, // 卖家
              { name: "STATUS" }, // 状态
              { name: "STATUSID", show: false }, // 状态
              { name: "ProductFlagList", show: false }, // 产品标签
              { name: "ProductFlagListName", width: 200 }, // 产品标签
              { name: "ProductName", width: 360 }, // 产品名称
              { name: "CreateTime", width: 160 }, // 下单时间
              { name: "ID", show: false }, // ID
              { name: "TradeTypeID", show: false }, // 交易方式
              { name: "SalePrice", show: false }, // 市场价格
              { name: "CostPrice", show: false }, // 商品单价
              { name: "EquityID", show: false }, // 权益ID
              { name: "UpdateTime", show: false }, // 更新时间
              { name: "PurchaserCompanyID", show: false }, // 买家ID
              { name: "UsersCount", show: false }, // 使用人数
              { name: "Remarks", show: false }, // 备注
              { name: "Mobile", show: false }, // 手机
              { name: "Contact", show: false }, // 联系人
              { name: "Integration", show: false }, // 使用积分
              { name: "RefundReasons", show: false }, // 售后原因
              { name: "RefundQuantity", show: false }, // 申请退货数量
              { name: "RefundAmount", show: false }, // 应退金额
              { name: "RefundCharge", show: false }, // 手续费
              { name: "Amount", show: false }, // 申请退款金额
              { name: "RefundPlatformID", show: false }, // 退款渠道
              { name: "RefundCreateTime", show: false }, // 申请退货时间
              { name: "UserPayTotalPrice", show: false }, // 购买金额
              {name: "RefundTime"},	// 退款到账时间
              { name: "RefundID", show: false }, // 退款订单id
              { name: "TypeID", show: false }, // 退款订单id
              { name: "UserCount", show: false }, // UserCount
              {name: "TradeTypeID", show: false},	// TradeTypeID
              {name: "IsRefundAudit", show: false},	// IsRefundAudit
              {name: "OutRefundCode", show: false}, //OutRefundCode
              {name: "PID", show: false},	// PID
              {name: "BtnStatusID", show: false},	// BtnStatusID
              {name: "PurchaseID", show: false},	// PurchaseID
              {name: "PayCode", show: false},	// PurchaseID
              
            ],
            paramData: {}
          },
          configWidth: 35,
          showNumber: true
        }
      },
      repetition: true,
      messageList: {},
      messageListAdd: {},
      rightList: []
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      const data = this.list.contract.data;
      let company = this.octopus.passport.authorization.company;
      data.paramData.CompanyID = company == 1 ? "NULL" : company;
    },
    showLookDiaolog(row) {
      this.messageList = row.data.row;
      const flag = this.messageList.ProductFlagList
        ? this.messageList.ProductFlagList.split(",")
        : [];
      const bool = flag.findIndex(item => item == 27) >= 0;

      let pageShow = 0;



      if ([1, 6,10, 40,13, 15, 17].includes(this.messageList.STATUSID)) {
        pageShow = 0;
      }
      if ([30,31, 32, 33].includes(this.messageList.STATUSID)) {
        pageShow = 1;
      }

      this.$nextTick(()=>{

        if(pageShow == 0){
          if (bool) {
            this.$refs.SalesOrderMsg_SPOMS.drawerOp(row.data.row.PurchaseID);
          } else {
            this.$refs.SalesOrderMsg.drawerOp(row.data.row.PurchaseID,'全部订单');
          }
        }

        if(pageShow == 1){
          if (bool) {
            this.$refs.AfterSaleOrderMsg_SPOMS.drawerOp(this.messageList.ID);
          } else {
            this.$refs.AfterSaleOrderMsg.drawerOp(this.messageList.ID,'全部订单1183');
          }
        }

      })

      // this.$nextTick(() => {
      //   // 判断订单状态显示不同状态的订单弹窗
      //   if (
      //     this.messageList.STATUSID != 32 &&
      //     this.messageList.STATUSID != 33
      //   ) {
      //     if (bool) {
      //       this.$refs.SalesOrderMsg_SPOMS.drawerOp();
      //     } else {
      //       // if(this.messageList.TypeID == 1) {
      //       this.$refs.SalesOrderMsg.drawerOp();
      //       // }
      //     }
      //   } else {
      //     if (bool) {
      //       this.$refs.AfterSaleOrderMsg_SPOMS.drawerOp();
      //     } else {
      //       this.$refs.AfterSaleOrderMsg.drawerOp();
      //     }
      //   }
      // });
    },
    output: function(data) {
      this.octopus.tips.success("下载完成。");
    },
    search: function(cell) {},
    save: function(data) {
      // 保存
      this.octopus.tips.success(data);
      // 刷新list
      this.list.contract.control.load();
      this.back();
    },
    back: function() {
      this.panel.visible = false;
    },
    del: function(row) {
      let o = this;
      // alert("del key: " + JSON.stringify(row));
      this.$confirm("此操作将永久删除该项, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.octopus.request.api.post(
            "/Octopus/Engine/Item",
            {
              id: 1188, // 菜单表的八爪鱼ID
              type: "DELETE",
              value: row.ID,
              cellData: [{ name: "ID", defaultValue: row.ID }]
            },
            // 处理回调事件，通过分析data.status.code的状态来实现。
            function(data) {
              if (data.status.code === 200) {
                o.list.contract.control.load();
              } else {
                o.octopus.tips.error(data);
              }
            }
          );
          this.$message({
            type: "success",
            message: "删除成功!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    refresh() {
      this.list.contract.control.load();
    }
  },
  props: ["oData"]
};
</script>
<style scoped>
.el-message-box {
  background-color: #fff !important;
}

.img_box {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.img_box img {
  width: 25px;
  cursor: pointer;
}
</style>
